<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <script src="../layui/layui.js" media="all"></script>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../js/jquery.1.9.1.js"></script>
		<!-- bootstrap的css核心，定义了很多的class -->
	<link rel="stylesheet" href="../assets/css/bootstrap.min.css" />
	<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
	<!-- 生成弹框、提示框、下拉菜单的 -->
	<script type="text/javascript" src="../assets/js/popper.min.js"></script>
	<!-- bootstrap的js，用于响应事件 -->
	<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
	<link rel="stylesheet" type="text/css" href="css/hotel.css"/>
	<!--引入bootstrap-table样式  -->
	<link href="css/bootstrap-table.css" rel="stylesheet">
	<!-- bootstrap-table.min.js -->
	<script src="js/bootstrap-table.js"></script>
	<!-- 引入中文语言包 -->
	<script src="js/bootstrap-table-zh-CN.js"></script>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<!-- 弹窗 -->
</head>

<body>
<table id="lists">
    <tr>
        <th>房间类型</th>
        <th>房间描述</th>
        <th>房间原价</th>
        <th>房间折扣</th>
    </tr>
    <tbody id="cars">
    </tbody>
    </tr>
</table>


<div class="layui-inline">
    <form class="layui-form" action="">
        <div class="layui-inline">
            <label class="layui-form-label">请输入预定天数：</label>
            <div class="layui-input-inline">
                <input type="text" name="daynum" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">到店时间</label>
            <div class="layui-input-inline">
                <input type="text" name="arrive_time" class="layui-input" id="arrive_time" lay-verify="required">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">预定房间数：</label>
            <div class="layui-input-inline">
                <input type="text" name="room_num" lay-verify="required" autocomplete="off" class="layui-input"
                       readonly="readonly">
            </div>
        </div>
        <div class="layui-hide">
            <input type="tel" name="room_type_id" class="layui-input">
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" id="empty" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['layer', 'form', 'laydate'], function () {
        var layer = layui.layer,
            laydate = layui.laydate,
            form = layui.form;

        laydate.render({
            elem: "#arrive_time",
            type: "datetime"
        });

        form.on('submit(formDemo)', function (data) {
            console.log(data.field);
            $.ajax({
                url:"../reserve/addReserveOnline",
                type:"post",
                data:{
                    room_type_id:data.field.roomtypeid,
                    room_num:data.field.room_num,
                    arrive_time:data.field.arrive_time,
                    daynum:data.field.daynum
                },
                success:function (resule) {
                    if (resule.code==200){
                        window.location.href='../order/alipay.html';
                    }else {
                        return false
                    }
                }
            })
        });
    });

    $(function () {
        $.ajax({
            url: "/SSMSD/cars/findcars",
            type: "post",
            dataType: "json",
            success: function (data) {
                var content = "";
                var a = 0;
                var room_type_id =0;
                var htmls="";
                for (var i = 0; i < data.length; i++) {
                    content += '<tr>'
                        + '<td>' + data[i].rt + '</td>'
                        + '<td>' + data[i].roomtrait + '</td>'
                        + '<td>' + data[i].roomprice + '</td>'
                        + '<td>' + data[i].discount + '</td>'
                        + '</tr>';
                    if (data[i].roomtypeid!=room_type_id){
                        htmls+=""+data[i].roomtypeid;
                        room_type_id =data[i].roomtypeid;
                    }
                }
                $("#cars").html(content);
                $("[name ='room_num']").val(data.length);
                $("[name = 'room_type_id']").val(htmls);

            }
        });
    })

    /* 清空购物车 */
    $("#empty").click(function(){
        $.ajax({
            url:"/SSMSD/cars/delete",
            type:"post",
            //ajax后台没有数据回来,如果加了data function就会以为是错误的不会执行
            success:function(){
                location.reload();
            }
        });
    })
</script>
</body>
</html>